package com.sefer.dragonfly.client.core.helper;

import java.io.Serializable;
import java.util.Iterator;
import java.util.ServiceLoader;

import com.sefer.dragonfly.client.core.cache.CmCache;
import com.sefer.dragonfly.client.core.cache.DefaultCmCache;

public class CmCacheFactory {

	public static <V extends Serializable> CmCache<V> createCmCache() {
		CmCache cache = null;
		ServiceLoader<CmCache> load = ServiceLoader.load(CmCache.class);
		Iterator<CmCache> iterator = load.iterator();
		if (iterator != null) {
			while (iterator.hasNext()) {
				cache = (CmCache) iterator.next();
			}
		}
		if (cache == null) {
			cache = new DefaultCmCache();
		}
		return cache;
	}

}
